package com.dwyinyuan.infrastructure.util.handler;

import com.baomidou.mybatisplus.core.handlers.*;
import lombok.extern.slf4j.*;
import org.apache.ibatis.reflection.*;
import org.springframework.stereotype.*;

import java.time.*;


/**
 * 微信公众号：笛舞音缘
 * <p>
 * 公共元数据处理器
 * <p>
 * Created by andy  on 2020-12-16.
 */
@Component
@Slf4j
public class CommonMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("新建时，开始填充系统字段！");

        this.strictInsertFill(metaObject, "created", LocalDateTime.class, LocalDateTime.now());
        this.strictInsertFill(metaObject, "modified", LocalDateTime.class, LocalDateTime.now());

        this.strictInsertFill(metaObject, "creator", String.class, "TODO 从上下文获取当前人");
        this.strictInsertFill(metaObject, "operator", String.class, "TODO 从上下文获取当前人");

        this.strictInsertFill(metaObject, "status", Integer.class, 0);
        this.strictInsertFill(metaObject, "version", Long.class, 1L);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("更新时，开始填充系统字段！");

        this.strictUpdateFill(metaObject, "modified", LocalDateTime.class, LocalDateTime.now());
        this.strictUpdateFill(metaObject, "operator", String.class, "TODO 从上下文获取修改人");
    }
}
